<template>
  <div class="record-plane">
    <div class="opers flex v-c">
      <el-form :inline="true" class="filter-blk flex-1">
        <el-form-item label="报警时间">
          <el-date-picker
            v-model="filterForm.alarmtime"
            type="date"
            placeholder="请选择"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="报警类型">
          <el-select
            v-model="filterForm.alarmType"
            placeholder="请选择"
            clearable
          >
            <el-option
              :label="item.name"
              :value="item.id"
              v-for="(item, key) in alarmType"
              :key="key"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="设备编号：">
          <el-input
            placeholder="请输入"
            type="text"
            v-model.trim="filterForm.number"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="searchAction"
            ><i class="iconfont icon-search"></i> 查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <el-table
      class="mt-20"
      :data="dataList"
      style="width: 100%"
      v-loading="loading"
    >
      <el-table-column
        prop="number"
        label="设备SN"
        width="155"
      ></el-table-column>
      <el-table-column
        prop="deviceTypeName"
        label="类型"
        width="80"
      ></el-table-column>
      <el-table-column
        prop="alarmTypeName"
        label="报警原因"
        width="100"
      ></el-table-column>
      <el-table-column
        prop="content"
        label="报警描述"
        width="180"
      ></el-table-column>
      <el-table-column
        prop="position"
        label="报警地点"
        width="100"
      ></el-table-column>
      <el-table-column prop="alarmtime" label="报警时间" width="150">
        <template slot-scope="scope">{{ scope.row.alarmtime }}</template>
      </el-table-column>
      <el-table-column
        prop="isHandleName"
        label="是否已处置"
        width="100"
      ></el-table-column>
      <el-table-column prop="infoconfirm" label="信息确认">
        <template slot-scope="scope">{{
          confirmObj[scope.row.infoconfirm]
        }}</template>
      </el-table-column>
      <!-- <el-table-column label="操作" width="220">
		    	<template slot-scope="scope">
		    		<div class="nowrap">
			    		<el-button :loading="viewing" type="green" @click="viewAction(scope.row)">点击查看</el-button>
		    		</div>	
		    	</template>
		    </el-table-column> -->
    </el-table>
    <el-pagination
      v-if="total > 0"
      class="text-right mt-20 mr-20"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-size="pageSize"
      layout="prev, pager, next, total, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>
<script>
export default {
  name: "recordPlan",
  props: {
    classify: {
      type: String,
      default: "",
    },
    id: {
      type: String,
      default: "",
    },
    number: {
      type: String,
      default: "",
    },
  },
  computed: {},
  watch: {},
  data() {
    return {
      type: this.$route.query.type,
      filterForm: {
        number: this.number,
      },
      typeList: [],
      alarmType: [
        {
          name: "所有类型",
          id: "",
        },
      ],
      loading: false,
      total: 0,
      loading: false,
      currentPage: 1,
      pageSize: 6,
      dataList: [],
      confirmObj: {
        "1": "报警",
        "2": "误报",
        "3": "测试",
      },
    };
  },
  methods: {
    getData(page) {
      let url =
        "/fireFightingIOT/historicalAlarmInfo/listHistoricalAlarmInfoListPage";
      this.loading = true;
      let params = Object.assign(
        {
          page: page,
          limit: this.pageSize,
          deviceClassify: this.classify == 100 ? "" : this.classify,
          deviceId: this.id,
        },
        this.filterForm
      );
      this.$get(url, params).then(
        (res) => {
          this.loading = false;
          this.closeFullLoading();
          let data = res.data;
          this.currentPage = page;
          this.total = data.totalSize;
          this.dataList = data.Items;
        },
        (err) => {
          this.loading = false;
          if (err.msg) {
            this.$message.error(err.msg);
          }
        }
      );
    },
    getAlarmType() {
      let url = "";
      let groupname = "";
      switch (this.type) {
        case "fire":
        case "chargingStation":
          url = "/electricfire/alarmInfo/dictList";
          groupname = "电气火灾监测报警类型";
          break;
        case "pool":
          url = "/firewater/alarmInfo/dictList";
          groupname = "建筑消防用水设备类型";
          break;
        case "smoke":
          url = "/independentsmoke/alarmInfo/dictList";
          groupname = "智慧独立烟感报警类型";
          break;
        case "monitor":
          url = "/firefightingvisualization/alarmInfo/dictList";
          groupname = "消防可视化监测报警类型";
          break;
        case "gas":
          url = "/combustiblegas/alarmInfo/dictList";
          groupname = "可燃气体监测报警类型";
          break;
        case "fireControl":
          url = "/fireFightingIOT/historicalAlarmInfo/dictList";
          groupname = "可燃气体监测报警类型";
          break;
      }
      if (!url) return;
      this.$get(url, {
        groupname: groupname,
      }).then(
        (res) => {
          this.alarmType = [...this.alarmType, ...res.data];
        },
        (err) => {
          //
        }
      );
    },
    searchAction() {
      this.getData(1);
    },
    handleCurrentChange(page) {
      this.getData(page);
    },
  },
  created() {
    this.getAlarmType();
    this.getData(1);
  },
};
</script>
